package com.forever7776.life.core.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.forever7776.life.core.common.vo.FriendlyLinkSearchVO;
import com.forever7776.life.core.entity.FriendlyLink;
import com.forever7776.life.core.mapper.FriendlyLinkMapper;
import com.forever7776.life.core.service.IFriendlyLinkService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 友情链接 服务实现类
 * </p>
 *
 * @author kz
 * @since 2018-03-23
 */
@Service
public class FriendlyLinkServiceImpl extends ServiceImpl<FriendlyLinkMapper, FriendlyLink> implements IFriendlyLinkService {

    @Autowired
    private FriendlyLinkMapper friendlyLinkMapper;

    /**
     * 根据搜索添加查询友情链接列表
     *
     * @param page
     * @param vo
     * @return
     */
    @Override
    public Page<FriendlyLink> selectAll(Page<FriendlyLink> page, FriendlyLinkSearchVO vo) {
        EntityWrapper<FriendlyLink> ew = new EntityWrapper<>();
        if (vo != null) {
            if (StringUtils.isNotEmpty(vo.getCompany())) {
                ew.like("company", vo.getCompany());
            }
            if (StringUtils.isNotEmpty(vo.getUrl())) {
                ew.like("url", vo.getUrl());
            }
            if (StringUtils.isNotEmpty(vo.getTel())) {
                ew.like("tel", vo.getTel());
            }
            if (vo.getStatus() != null) {
                ew.eq("status", vo.getStatus());
            }
        }
        ew.orderBy("sort",false);

        return selectPage(page, ew);
    }

    /**
     * 修改友情链接状态
     *
     * @param id
     * @param status
     * @return
     */
    @Override
    public Integer updateLinkStatus(Integer id, Integer status) {
        return friendlyLinkMapper.updateLinkStatus(id, status);
    }
}
